package oneway01;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer2 {

    public static void main(String[] args) throws Exception {
        // 1.创建生产者
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("Producer_pethome_group");
        // 2.设置地址调度均衡
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        // 3.启动实例
        defaultMQProducer.start();
        // 4.设置消息内容
        Message message = new Message("pethome_topic", "pethome_tags", "我在家里做作业,单向发送".getBytes(StandardCharsets.UTF_8));
        // 5.发送消息
        defaultMQProducer.sendOneway(message);
        // 6.关闭生产者
        defaultMQProducer.shutdown();
    }
}
